package com.hxkcloud.patient.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.beans.OrderBean;

import java.util.List;

/**
 * Created by Administrator on 2017/4/23.
 */

public class TransactionAdapter extends BaseAdapter {
    private Context context;
    private List<OrderBean> data;

    public TransactionAdapter(Context context, List<OrderBean> data) {
        this.context = context;
        this.data = data;
    }

    public void setData(List<OrderBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }
    public void clearData(){
        data.clear();
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.transaction_adapter_item,null);
            holder = new ViewHolder();
            holder.tv_monery = (TextView) convertView.findViewById(R.id.monery_text);
            holder.tv_number = (TextView) convertView.findViewById(R.id.number_text);
            holder.tv_ordernumber = (TextView) convertView.findViewById(R.id.ordernumber);
            holder.tv_status = (TextView) convertView.findViewById(R.id.status_text);
            holder.tv_time = (TextView) convertView.findViewById(R.id.time_text);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (data.get(position).getIsexcess()==0){
            holder.tv_status.setText("已完成");
        }else {
            holder.tv_status.setText("未完成");
        }
        holder.tv_time.setText(data.get(position).getTime());

        holder.tv_ordernumber.setText(data.get(position).getOrder());
        holder.tv_number.setText(data.get(position).getCount()+"");
        holder.tv_monery.setText("¥"+data.get(position).getFee());
        return convertView;
    }
  static  class ViewHolder{
        TextView tv_status;
        TextView tv_ordernumber;
        TextView tv_monery;
        TextView tv_time;
        TextView tv_number;
    }
}
